/*
 * Teknei 2014 - All rights reserved
 */
package com.teknei.acabus.example.facade.impl;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.teknei.acabus.FacadeException;
import com.teknei.acabus.ServiceException;
import com.teknei.acabus.core.entities.TableA;
import com.teknei.acabus.core.entities.TableB;
import com.teknei.acabus.dto.TableCDTO;
import com.teknei.acabus.example.facade.TableFacade;
import com.teknei.acabus.example.services.TableAService;
import com.teknei.acabus.example.services.TableBService;
import com.teknei.acabus.example.services.TableCService;

/**
 * Session Bean implementation class TableFacadeBean
 * @author Jorge Amaro
 * @version 1.0
 * @since 1.0
 */
@Stateless
public class TableFacadeBean implements TableFacade {

	@EJB
	private TableAService serviceTableA;
	@EJB
	private TableBService serviceTableB;
	@EJB
	private TableCService serviceTableC;

	private static final Logger LOG = LoggerFactory
			.getLogger(TableFacadeBean.class);


	/* (non-Javadoc)
	 * @see com.teknei.acabus.example.facade.TableFacade#findAllTableA()
	 */
	@Override
	public List<TableA> findAllTableA() throws FacadeException {
		try {
			List<TableA> list = serviceTableA.findAll();
			return list;
		} catch (ServiceException e) {
			throw new FacadeException("Error in findAllTableA:"
					+ e.getMessage(), e);
		}
	}

	/* (non-Javadoc)
	 * @see com.teknei.acabus.example.facade.TableFacade#findAllTableB()
	 */
	@Override
	public List<TableB> findAllTableB() throws FacadeException {
		try {
			List<TableB> list = serviceTableB.findAll();
			return list;
		} catch (ServiceException e) {
			throw new FacadeException("Error in findAllTableB:"
					+ e.getMessage(), e);
		}
	}

	/* (non-Javadoc)
	 * @see com.teknei.acabus.example.facade.TableFacade#findAllTableCDTO()
	 */
	@Override
	public List<TableCDTO> findAllTableCDTO() throws FacadeException {
		try {
			List<TableCDTO> list = serviceTableC.findAll();
			return list;
		} catch (ServiceException e) {
			throw new FacadeException("Error in findAllTableCDTO:"
					+ e.getMessage(), e);
		}
	}

	/* (non-Javadoc)
	 * @see com.teknei.acabus.example.facade.TableFacade#updateTableA(com.teknei.acabus.core.entities.TableA)
	 */
	@Override
	public void updateTableA(TableA tablea) throws FacadeException {
		try {
			serviceTableA.update(tablea);
		} catch (ServiceException e) {
			throw new FacadeException(
					"Error in updateTableA:" + e.getMessage(), e);
		}
	}

	/* (non-Javadoc)
	 * @see com.teknei.acabus.example.facade.TableFacade#updateTableB(com.teknei.acabus.core.entities.TableB)
	 */
	@Override
	public void updateTableB(TableB tableb) throws FacadeException {
		try {
			serviceTableB.update(tableb);
		} catch (ServiceException e) {
			throw new FacadeException(
					"Error in updateTableB:" + e.getMessage(), e);
		}
	}

	/* (non-Javadoc)
	 * @see com.teknei.acabus.example.facade.TableFacade#updateTableC(com.teknei.acabus.dto.TableCDTO)
	 */
	@Override
	public void updateTableC(TableCDTO tablec) throws FacadeException {
		try {
			serviceTableC.update(tablec);
		} catch (ServiceException e) {
			throw new FacadeException(
					"Error in updateTableC:" + e.getMessage(), e);
		}
	}

	/* (non-Javadoc)
	 * @see com.teknei.acabus.example.facade.TableFacade#saveTableA(com.teknei.acabus.core.entities.TableA)
	 */
	@Override
	public int saveTableA(TableA tablea) throws FacadeException {
		try {
			int pk = serviceTableA.save(tablea);
			return pk;
		} catch (ServiceException e) {
			throw new FacadeException("Error in addTableA:" + e.getMessage(), e);
		}
	}

	/* (non-Javadoc)
	 * @see com.teknei.acabus.example.facade.TableFacade#saveTableB(com.teknei.acabus.core.entities.TableB)
	 */
	@Override
	public int saveTableB(TableB tableb) throws FacadeException {
		try {
			int pk = serviceTableB.save(tableb);
			return pk;
		} catch (ServiceException e) {
			throw new FacadeException("Error in saveTableB:" + e.getMessage(),
					e);
		}
	}

	/* (non-Javadoc)
	 * @see com.teknei.acabus.example.facade.TableFacade#saveTableC(com.teknei.acabus.dto.TableCDTO)
	 */
	@Override
	public int saveTableC(TableCDTO tableb) throws FacadeException {
		try {
			int pk = serviceTableC.save(tableb);
			return pk;
		} catch (ServiceException e) {
			throw new FacadeException("Error in saveTableC:" + e.getMessage(),
					e);
		}
	}

	/* (non-Javadoc)
	 * @see com.teknei.acabus.example.facade.TableFacade#deleteTableA(com.teknei.acabus.core.entities.TableA)
	 */
	@Override
	public void deleteTableA(TableA tablea) throws FacadeException {
		try {
			serviceTableA.delete(tablea);
		} catch (ServiceException e) {
			throw new FacadeException("Error in addTableA:" + e.getMessage(), e);
		}
	}

	/* (non-Javadoc)
	 * @see com.teknei.acabus.example.facade.TableFacade#deleteTableB(com.teknei.acabus.core.entities.TableB)
	 */
	@Override
	public void deleteTableB(TableB tableb) throws FacadeException {
		try {
			serviceTableB.delete(tableb);
		} catch (ServiceException e) {
			throw new FacadeException("Error in addTableB:" + e.getMessage(), e);
		}
	}

	/* (non-Javadoc)
	 * @see com.teknei.acabus.example.facade.TableFacade#deleteTableC(com.teknei.acabus.dto.TableCDTO)
	 */
	@Override
	public void deleteTableC(TableCDTO tablec) throws FacadeException {
		try {
			serviceTableC.delete(tablec);
		} catch (ServiceException e) {
			throw new FacadeException(
					"Error in deleteTableC:" + e.getMessage(), e);
		}
	}

	/**
	 * @return the serviceTableA
	 */
	public TableAService getServiceTableA() {
		return serviceTableA;
	}

	/**
	 * @param serviceTableA
	 *            the serviceTableA to set
	 */
	public void setServiceTableA(TableAService serviceTableA) {
		this.serviceTableA = serviceTableA;
	}

	/**
	 * @return the serviceTableB
	 */
	public TableBService getServiceTableB() {
		return serviceTableB;
	}

	/**
	 * @param serviceTableB
	 *            the serviceTableB to set
	 */
	public void setServiceTableB(TableBService serviceTableB) {
		this.serviceTableB = serviceTableB;
	}

	/**
	 * @return the serviceTableC
	 */
	public TableCService getServiceTableC() {
		return serviceTableC;
	}

	/**
	 * @param serviceTableC
	 *            the serviceTableC to set
	 */
	public void setServiceTableC(TableCService serviceTableC) {
		this.serviceTableC = serviceTableC;
	}

}
